#include "samename.h"
#include "ui_samename.h"
#include <QDebug>
#include <QSqlQuery>
#include <QSqlQueryModel>
samename::samename(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::samename)
{
    ui->setupUi(this);





    ui->table->setSelectionBehavior(QAbstractItemView::SelectRows);

    ui->table->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

samename::~samename()
{
    delete ui;
}

void samename::on_pushButton_clicked()//重名干部查询
{
    QString name=ui->nametext->text();
    //QSqlQueryModel *mod = new QSqlQueryModel(this);

    QSqlQuery query;
    //mod->setQuery(QString("select CadreName,IDNum from CadreInfo where CadreName='%1'").arg(name));

    query.exec(QString("select CadreName,IDNum from CadreInfo where CadreName='%1'").arg(name));//where定义查询条件

    while(query.next())
    {

        int rowcount=ui->table->rowCount();//有几列
        ui->table->insertRow(rowcount);//加一行table

        QString CadreName=query.value(0).toString();//0
        ui->table->setItem(rowcount,0,new QTableWidgetItem(CadreName));

        QString IDNum=query.value(1).toString();//1
        ui->table->setItem(rowcount,1,new QTableWidgetItem(IDNum));
    }



}
